Skip to content

feat: implement course progress persistence - #115

Merged
ayomideadeniran merged 8 commits into
StellarDevHub:mainfrom
emmanuelist:feat/course-progress-persistence
Mar 27, 2026
Merged

feat: implement course progress persistence#115
ayomideadeniran merged 8 commits into
StellarDevHub:mainfrom
emmanuelist:feat/course-progress-persistence

Conversation

@emmanuelist

Copy link
Copy Markdown
Contributor

Closes #35

Implements database-backed course progress persistence. Previously, learning.service.ts used an in-memory Map that lost all progress on server restart. Now everything goes through Prisma → PostgreSQL.

What changed

New file: backend/src/learning/progress.ts

  • getProgress(studentId) — retrieves persisted progress from PostgreSQL via Prisma, returns defaults for new students
  • recordStageCompletion({ studentId, stageId, moduleId }, totalLessons) — idempotently records a completed stage, recalculates percentage
  • resetProgress(studentId) — clears all progress for a student
  • Flexible CompletedStage and StudentProgress interfaces designed for future module types (quizzes, projects, etc.)

Updated: backend/src/routes/learning/learning.service.ts

  • Replaced in-memory Map storage with calls to the new progress.ts persistence module
  • getStudentProgress and updateProgress now delegate to Prisma-backed functions

Updated: backend/src/routes/learning/learning.routes.ts

  • Routes now use the service layer instead of inline Prisma calls
  • Tracks which module a completed lesson belongs to
  • Removed direct prisma import — all DB access goes through the service

New file: backend/tests/progress.test.ts

  • Integration tests covering: default progress for new students, persisted progress retrieval, lesson completion, idempotency, percentage calculation, module tracking, validation errors, and data flexibility

Requirements from issue

  • Create backend/src/learning/progress.ts
  • Implement a function to record completed stages for a student ID
  • Ensure the data structure is flexible for future modules (CompletedStage interface with stageId, moduleId, completedAt)

Data structure

// Flexible stage tracking — works for lessons, quizzes, projects, etc.
interface CompletedStage {
  stageId: string;
  completedAt: string;   // ISO 8601
  moduleId: string;
}

interface StudentProgress {
  userId: string;
  completedLessons: string[];
  completedStages: CompletedStage[];
  currentModule: string;
  percentage: number;
  lastActivityAt: string;
}

How to test

cd backend
npm test -- --testPathPattern=progress

- Regenerate backend/package-lock.json (missing deps from lock file)
- Fix rustfmt formatting in contracts/src/token.rs (multi-line use statement)
- Replace 'any' types with proper types in frontend (no-explicit-any lint errors)
  - auth/login, auth/register, verify, certificates pages: catch(err: unknown)
  - AuthContext: catch(err: unknown) with instanceof Error narrowing
  - api.ts: Promise<Record<string, unknown>> for untyped API responses
  - soroban.ts: eslint-disable for unavoidable SDK type assertion
- Backend: remove unused catch variables across routes, fix no-explicit-any errors
- Backend: clean up unused imports (adapter, loginSchema, PrismaPg)
- Frontend: add proper TypeScript interfaces for dashboard, feedback, certificate APIs
- Frontend: fix react/no-unescaped-entities in ideas/page.tsx
- Frontend: fix verificationResult type annotation in certificates page
@emmanuelist
emmanuelist force-pushed the feat/course-progress-persistence branch from 5365134 to 7a236e8 Compare March 26, 2026 12:06
- Backend: fix no-explicit-any in enrollments.ts, routes/index.ts, tests
- Backend: remove unused catch(error) variables in learning.routes.ts
- Backend: replace @ts-ignore with @ts-expect-error in generator.test.ts
- Frontend: run Prettier --write to fix formatting in 20 files
@ayomideadeniran
ayomideadeniran merged commit 4019848 into StellarDevHub:main Mar 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants